using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class NodeRelationMap : EntityTypeConfiguration<NodeRelation>
    {
        public NodeRelationMap()
        {
            // Primary Key
            this.HasKey(t => new { t.FromNodeId, t.ToNodeId });

            // Properties
            this.Property(t => t.FromNodeId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.ToNodeId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Name)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("NodeRelations");
            this.Property(t => t.FromNodeId).HasColumnName("FromNodeId");
            this.Property(t => t.ToNodeId).HasColumnName("ToNodeId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.FlowId).HasColumnName("FlowId");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");

            // Relationships
            this.HasRequired(t => t.Flow)
                .WithMany(t => t.NodeRelations)
                .HasForeignKey(d => d.FlowId);
            this.HasRequired(t => t.Node)
                .WithMany(t => t.NodeRelations)
                .HasForeignKey(d => d.ToNodeId);
            this.HasRequired(t => t.Node1)
                .WithMany(t => t.NodeRelations1)
                .HasForeignKey(d => d.FromNodeId);

        }
    }
}
